from selenium import webdriver
import os, time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 等待
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"  # 浏览器驱动位置
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get('http://www.baidu.com')

# 显式等待 expected_conditions类有很多预期条件的判断方法
# input2 = WebDriverWait(driver, 5, 0.5).until(EC.presence_of_element_located((By.ID, 'kw')))
# input2.send_keys('selenium')
# driver.quit()


try:
    el = driver.find_element_by_id('kw')
    if el.is_displayed():
        print('get it')
    else:
        print('time out')
except:
    print(time.time())
finally:
    driver.quit()
# 隐式等待
driver.implicitly_wait(10)

# 休眠
time.sleep(5)